#include "fuzzy_output.h"

FuzzyOutput::FuzzyOutput()
{
}


double FuzzyOutput::veryBad(double value, double ceiling)
{
    double pertinence;
    double inflection = 10 + ((-20*ceiling) + 20);

    //qDebug() << inflection; // imprimir o ponto de inflection

    if (value  <   inflection )
    {
        pertinence = ceiling;
    }
    if (value >= inflection && value < 30)
    {
        pertinence = ((-(value-10)+20)/20);
        //qDebug() << result;
    }
    if(value >=30)
    {
            pertinence = 0.0;
    }

    return(pertinence);
}

double FuzzyOutput::bad(double value, double ceiling)
{
    double pertinence;

    double inflection1 = 10 + (20*ceiling);
    double inflection2 = 30 + ((-20*ceiling) + 20);

    if (value  <   10 )
    {
        pertinence = 0.0;
    }
    if (value >= 10 && value < inflection1)
    {
        pertinence = ((value-10)/20);
        //qDebug() << result;
    }
    if (value >= inflection1 && value < inflection2)
    {
        pertinence = ceiling;
    }
    if(value >= inflection2 && value < 50)
    {
        pertinence = ((-(value-30)+20)/20);
        //qDebug() << result;

    }
    if (value  >= 50 )
    {
        pertinence = 0.0;
    }

    return(pertinence);
}

double FuzzyOutput::medium(double value, double ceiling)
{
    double pertinence;

    double inflection1 = 30 + (20*ceiling);
    double inflection2 = 50 + ((-20*ceiling) + 20);

    if (value  <   30 )
    {
        pertinence = 0.0;
    }
    if (value >= 30 && value < inflection1 )
    {
        pertinence = ((value-30)/20);
        //qDebug() << result;
    }
    if (value >= inflection1 && value < inflection2 )
    {
        pertinence = ceiling;
        //qDebug() << result;
    }

    if(value >= inflection2 && value < 70)
    {
        pertinence = ((-(value-50)+20)/20);
        //qDebug() << result;

    }
    if (value  >= 70 )
    {
        pertinence = 0.0;
    }

    return(pertinence);
}

double FuzzyOutput::good(double value, double ceiling)
{
    double pertinence;

    double inflection1 = 50 + (20*ceiling);
    double inflection2 = 70 + ((-20*ceiling) + 20);

    if (value  <   50 )
    {
        pertinence = 0.0;
    }
    if (value >= 50 && value < inflection1)
    {
        pertinence = ((value-50)/20);
        //qDebug() << result;
    }
    if(value >= inflection1 && value < inflection2)
    {
        pertinence = ceiling;

    }
    if(value >= inflection2 && value < 90)
    {

        pertinence = ((-(value-70)+20)/20);
        //qDebug() << result;

    }
    if (value  >= 90 )
    {
        pertinence = 0.0;
    }

    return(pertinence);
}

double FuzzyOutput::veryGood(double value, double ceiling)
{
    double pertinence;
    double inflection = 70 + (20*ceiling);


    if (value  <   70 )
    {
        pertinence = 0.0;
    }
    if (value >= 70 && value < inflection)
    {
        pertinence = ((value-70)/20);
        //qDebug() << result;
    }
    if(value >=inflection)
    {
            pertinence =ceiling;
    }

    return(pertinence);
}

